(function ($) {
    $.include(webRoot + '/resources/console/extra/layer/skin/', ["layer.css"]);
    $.getScript(webRoot + '/resources/console/extra/layer/layer.js').done(function () {
        $.extend({
            layer: layer,
            showDialog: function (option) {
                if (option.url == '' || option.url == null) {
                    return;
                }
                if (option.title == '' || option.title == null) {
                    option.title = "提示框";
                }
                if (option.width == '' || option.width == null) {
                    option.width = '600';
                }
                if (option.height == '' || option.height == null) {
                    option.height = '400';
                }

                var config = {
                    title: option.title,
                    maxmin: false,
                    resize: false,
                    move: false,
                    type: 2,
                    content: option.url,
                    area: [option.width + "px", option.height + "px"],
                    btn: option.btn,
                    skin: 'layui-layer-lan',
                    end: function () {
                        var fn = option.closeCallBack;
                        if (fn != null && typeof (eval(fn)) == "function") {
                            fn();
                        }
                    },
                    success: function (layero, index) {
                        var fn = option.successCallBack;
                        if (fn != null && typeof (eval(fn)) == "function") {
                            var frame = window[layero.find('iframe')[0]['name']];
                            fn(frame);
                        }
                    }
                };

                $.extend(config, option.events);

                var dialog = layer.open(config);

                var getHeight = function () {
                    if (window.innerHeight != undefined) {
                        return window.innerHeight;
                    } else {
                        return document.documentElement.clientHeight;
                    }
                };

                var getWidth = function () {
                    if (window.innerHeight != undefined) {
                        return window.innerWidth;
                    } else {
                        return document.documentElement.clientWidth;
                    }
                };

                var height = getHeight();
                var width = getWidth();
                if (width <= 1024 || height <= 768) {
                    layer.full(dialog);
                }
                return dialog;
            },
            openLoading: function () {
                return layer.load(1, {
                    shade: [0.1, '#AAAAAA']
                });
            },
            closeLoading: function (loading) {
                layer.close(loading);
            },
            closeAll: function () {
                layer.closeAll();
                if (window.parent)
                    window.parent.layer.closeAll();
            },
            photos: function (id, imgUrl) {
                if (imgUrl) {
                    $.getScript(webRoot + '/resources/console/extra/layer/extend/layer.ext.js').done(function () {
                        var curImgUrlArr = imgUrl.split(",");
                        var datas = new Array();
                        for (var i = 0, len = curImgUrlArr.length; i < len; i++) {
                            var data = new Object();
                            data.alt = curImgUrlArr[i] + i;
                            data.pid = curImgUrlArr[i] + i;
                            data.src = pictureRoot + "/" + curImgUrlArr[i];
                            data.thumb = curImgUrlArr[i];

                            datas.push(data);
                        }
                        var json = {
                            "title": "图片预览", //相册标题
                            "id": id, //相册id
                            "start": 0 //初始显示的图片序号，默认0
                        };
                        json.data = datas;

                        layer.photos({
                            photos: json,
                            anim: 5
                        });
                    });
                }
            }
        });
    });
})(jQuery);